import { request, parseTime } from "../../utils/util";

Page({
  data: {
    message: []
  },
  toDetail (ev) {
    let { id } = ev.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/messageDetail/index?id=${id}`
    })
  },
  // 获取列表数据
  getList() {
    request({
      url: '/api/web/messages',
      success: ({ code, data }) => {
        if (code === 200) {
          this.setData({
            message: data.map(item => {
              item.created_at_show = parseTime(item.created_at, '{y}/{m}/{d} {h}:{i}')
              return item
            })
          })
        }
      }
    })
  },
  onShow () {
    wx.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#000000',
      animation: {
        duration: 400,
        timingFunc: 'easeIn'
      }
    })
    this.getList()
  }
})
